<?php defined("MAIN_DIR") or die("No direct access");

$limit = 10;
$page = UV::rInt(strip_tags($route->GET("page")));
if ($page < 1){
	$page = 1;
}

$query = "select SQL_CALC_FOUND_ROWS `B`.*,`U`.`login`
    from `books` as `B`
    left join `users` as `U`
        on `B`.`user_id` = `U`.`id`
    where
        `B`.`status` = 'placed'
    group by `B`.`id`
    limit 100";
$list = $db->getTable($query);

$count = count($list);
$all_count = $db->getCell("SELECT FOUND_ROWS()");

require_once ADMIN.HEADFILE;
?>

<h1>Книги <a href='/admin/books/add/' class='button'>Добавить книгу</a></h1>

<?php
if ($count){
	echo "<table class='statistics'>";
	echo "<tr><td class='c'>ID</td><td>Название</td><td>Добавил</td><td>Ссылки</td><td>Действия</td></tr>";
	foreach ($list as $book) {
		echo "<tr>";
        echo "<td>".$book['id']."</td>";
		echo "<td class='text'>";
			echo "<p>".$book['name']."</p>";
		echo "</td>";
		echo "<td>".$book['login']."</td>";
		echo "<td>";
            echo "<p><b>OZON</b> <a class='action-edit' target='_blank' href='{$book['ozon']}'>".$book['ozon']."</a></p>";
            echo "<p><b>Books</b> <a class='action-edit' target='_blank' href='{$book['books']}'>".$book['books']."</a></p>";
        echo "</td>";
		echo "<td>";
			echo "<a class='action-edit' href='/admin/books/edit/{$book['id']}'><img src='/files/img/admin/edit.png' alt='Редактировать' title='Редактировать'></a> ";
			echo "<a class='action-trash' href='/admin/books/actions?action=trash&id[]={$book['id']}'><img src='/files/img/admin/trash.png' alt='Удалить' title='Удалить'></a>";
		echo "</td>";
		echo "</tr>";
	}
	echo "</table>";
}
echo showPages($all_count, $limit);

require_once ADMIN.FOOTERFILE; ?>